<template>
	<form class="memberItem" @submit="formSubmit">
		<view class="uni-form-item uni-column">
			<view class="title">成员名字</view>
			<view class="item">
				<input placeholder-style="font-size: 10px;" type="text" name="person_name" placeholder="如:张三, 李四" :value="memberDetail.person_name" />
			</view>
		</view>
		<view class="uni-form-item uni-column">
			<view class="title">成员身份证号</view>
			<view class="item">
				<input placeholder-style="font-size: 10px;" type="idcard" name="person_identity" placeholder="成员身份证" :value="memberDetail.person_identity" />
			</view>
		</view>
		<view class="uni-form-item uni-column">
			<view class="title">是否开放成员注册（默认开放）</view>
			<view class="item">
				<radio-group name="person_sex">
					<label>
						<radio :checked="memberDetail.person_sex == 1" value="1" />男</label>
					<label>
						<radio :checked="memberDetail.person_sex == 2" value="2" />女</label>
					<label>
						<radio :checked="memberDetail.person_sex == 3" value="3" />保密</label>
				</radio-group>
			</view>
		</view>
		<view class="uni-form-item uni-column">
			<view class="title">成员编号</view>
			<view class="item">
				<input placeholder-style="font-size: 10px;" type="text" name="person_num" placeholder="学号、工号等" :value="memberDetail.person_num" />
			</view>
		</view>
		<view class="uni-form-item uni-column">
			<view class="title">成员备注</view>
			<view class="item">
				<input placeholder-style="font-size: 10px;" type="text" name="person_remark" placeholder="如部门中的某分组不再建立团体，就写入备注" :value="memberDetail.person_remark" />
			</view>
		</view>
		<view class="uni-btn-v">
			<button :loading="false" form-type="submit">提交修改</button>
		</view>
	</form>
</template>

<script>
	export default {
		data() {
			return {
				group_id: '',
				member_id: '',
				memberDetail: {}
			}
		},
		onLoad() {
			this.group_id = this.$route.query.group_id;
			this.member_id = this.$route.query.member_id;
			if (this.group_id && this.member_id) {
				this.getOneMember(this.member_id);
			}
		},
		methods: {
			getOneMember(member_id) {
				uniCloud.callFunction({
					name: "ha_get_one_member",
					data: { member_id },
					success: ({result}) => {
						console.log(result);

						if(result.status === 0){
							this.memberDetail = result.data;
						}else{
							uni.showToast({
								icon: 'none',
								title: `${result.msg || "网络异常，请稍后重试！"}`,
								duration: 1000
							});
						}
					},
					fail() {
						uni.showToast({
							icon: 'none',
							title: '网络异常，请稍后重试！'
						});
					}
				});
			},
			formSubmit(e) {
				console.log(e.detail.value);

				uniCloud.callFunction({
					name: "ha_update_member",
					data: Object.assign(e.detail.value, {
						group_id: this.group_id,
						member_id: this.member_id
					}),
					success: ({result}) => {
						console.log(result);

						if ( result.status === 0 ) {
							uni.showToast({
								title: `${result.msg || "更新成功！"}`,
								duration: 1000
							});
							// location.reload();
							// uni.navigateTo({
							// 	url: './member_manage?group_id=' + this.group_id
							// });
						} else {
							uni.showToast({
								icon: 'none',
								title: `${result.msg || "网络异常，请稍后重试！"}`,
								duration: 1000
							});
						}
					},
					fail() {
						uni.showToast({
							icon: 'none',
							title: '网络异常，请稍后重试！'
						});
					}
				});
			}
		}
	}
</script>

<style>
	.uni-form-item {
		padding: 5rpx 0;
	}

	.memberItem__name {
		height: 50rpx;
		border: 1rpx solid #666;
	}

	.memberItem .item {
		padding: 5rpx 12rpx;
	}

	.memberItem .item input {
		padding-left: 24rpx;
		height: 80rpx;
		border: 1rpx solid rgba(102, 102, 102, 0.5);
	}

	.memberItem .text {
		font-size: 14px;
	}

	view {
		color: #666 !important;
	}
</style>
